package nerdicide.experiments.reasoning;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

/**
 * 
 * @author Brent Kersanske
 *
 */
public class UnfamiliarWordPool {
	
	private static String MSG_ERROR_ABOVE_CURRENT_THRESHOLD = "[ERROR] Requested map size of {0} is above the amount of unfamiliar {1} currently used {2}";
	
	public static String VERB_ENCODING    = "<verb";
	public static String NOUN_ENCODING    = "<noun";
	public static String CLOSURE_ENCODING = ">";
	
	private static ArrayList<String> unfamiliarNouns = new ArrayList<String> ();
	private static ArrayList<String> unfamiliarVerbs = new ArrayList<String> ();
	
	static {
		
		/* Add 20 unfamiliar nouns to the word pool. */
		unfamiliarNouns.add("blorgle");
		unfamiliarNouns.add("threehad");
		unfamiliarNouns.add("tourbay");
		unfamiliarNouns.add("donfly");
		unfamiliarNouns.add("erablow");
		unfamiliarNouns.add("meershwab");
		unfamiliarNouns.add("beenbo");
		unfamiliarNouns.add("inyag");
		unfamiliarNouns.add("purwag");
		unfamiliarNouns.add("dinyuck");
		unfamiliarNouns.add("fraible");
		unfamiliarNouns.add("nongrea");
		unfamiliarNouns.add("cronblarg");
		unfamiliarNouns.add("desbop");
		unfamiliarNouns.add("reafwert");
		unfamiliarNouns.add("batbogg");
		unfamiliarNouns.add("vegmite");
		unfamiliarNouns.add("groterie");
		unfamiliarNouns.add("xenaball");
		unfamiliarNouns.add("nardup");
		
		/* Add 20 unfamiliar verbs to the word pool. */
		unfamiliarVerbs.add("mershify");
		unfamiliarVerbs.add("osipy");
		unfamiliarVerbs.add("duperate");
		unfamiliarVerbs.add("yaggle");
		unfamiliarVerbs.add("durfer");
		unfamiliarVerbs.add("breefole");
		unfamiliarVerbs.add("eracketoor");
		unfamiliarVerbs.add("rooblesnatch");
		unfamiliarVerbs.add("creedobble");
		unfamiliarVerbs.add("moof");
		unfamiliarVerbs.add("zarify");
		unfamiliarVerbs.add("harshear");
		unfamiliarVerbs.add("febrooze");
		unfamiliarVerbs.add("prinpraw");
		unfamiliarVerbs.add("durble");
		unfamiliarVerbs.add("tanarate");
		unfamiliarVerbs.add("jambeezle");
		unfamiliarVerbs.add("narddawgify");
		unfamiliarVerbs.add("ablear");
		unfamiliarVerbs.add("pholock");
		
	}
	
	public static HashMap<String, String> generateUnfamiliarVerbMap(int size) throws IllegalArgumentException {
		if(size < unfamiliarVerbs.size()) {
			Random r = new Random();
			HashMap<String, String> unfamiliarVerbMap = new HashMap<String, String> ();
			while(size > 0) {
				String randomUnfamiliarVerb = unfamiliarVerbs.get(r.nextInt(unfamiliarVerbs.size() - 1));
				if(!unfamiliarVerbMap.containsValue(randomUnfamiliarVerb)) {
					String keyIndex = String.valueOf(unfamiliarVerbMap.size() + 1);
					unfamiliarVerbMap.put(VERB_ENCODING.concat(keyIndex).concat(CLOSURE_ENCODING), randomUnfamiliarVerb);
					size--;
				}
			}
			return unfamiliarVerbMap;
		} else {
			throw new IllegalArgumentException(MessageFormat.format(MSG_ERROR_ABOVE_CURRENT_THRESHOLD, size, "verbs", unfamiliarVerbs.size()));
		}
	}
	
	public static HashMap<String, String> generateUnfamiliarNounMap(int size) throws IllegalArgumentException {
		if(size < unfamiliarNouns.size()) {
			Random r = new Random();
			HashMap<String, String> unfamiliarNounMap = new HashMap<String, String> ();
			while(size > 0) {
				String randomUnfamiliarNoun = unfamiliarNouns.get(r.nextInt(unfamiliarNouns.size() - 1));
				if(!unfamiliarNounMap.containsValue(randomUnfamiliarNoun)) {
					String keyIndex = String.valueOf(unfamiliarNounMap.size() + 1);
					unfamiliarNounMap.put(NOUN_ENCODING.concat(keyIndex).concat(CLOSURE_ENCODING), randomUnfamiliarNoun);
					size--;
				}
			}
			return unfamiliarNounMap;
		} else {
			throw new IllegalArgumentException(MessageFormat.format(MSG_ERROR_ABOVE_CURRENT_THRESHOLD, size, "nouns", unfamiliarNouns.size()));
		}
	}	
}
